import requests
from bs4 import BeautifulSoup
from threading import Thread
import fake_useragent
# 首先实例化fake_useragent对象
ua = fake_useragent.UserAgent()
movlistdata = []
def getmovlist():
    url = "https://yyets.com/movies/"
    headers = {
        "User-Agent":ua.chrome
    }
    a = requests.get(url,headers=headers).text
    # with open("xx.html","w") as f:
    #     f.write(str(a.text))
    sou = BeautifulSoup(a,"html.parser")
    # sou = BeautifulSoup(a, 'lxml')
    movlist = sou.select(".item.movies")
    # movlist = sou.findAll(".load_modules")
    for i in movlist:
        herf = i.a.get("href")
        src = i.img.get("src")
        name = i.img.get("alt")
        data = {"name":name,"src":src,"herf":herf}
        movlistdata.append(data)
        thread = Thread(target=getmovesrc,args=(herf,))
        thread.start()
def getmovesrc(herf):
    a = requests.get(herf).text
    sou = BeautifulSoup(a,"html.parser")
    try:
        player = sou.select("#playcontainer iframe")[0]
        mp4src = player.get("src")
        print(mp4src)
    except IndexError:
        print("没有")

if __name__ == '__main__':
    getmovlist()
    # getmovesrc("https://yyets.com/movies/170055/")